home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / jockey / handlers / sl_modem.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.4 KB  |  67 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import os.path as os
  6. import logging
  7. import subprocess
  8. from jockey.handlers import Handler
  9.  
  10. def _(x):
  11.     return x
  12.  
  13.  
  14. class SlModem(Handler):
  15.     
  16.     def __init__(self, backend):
  17.         Handler.__init__(self, backend, name = _('Software modem'), rationale = _('This driver enables the usage of many software modems, as commonly found in laptops.\n\nIf this driver is not enabled, you will not be able to use your modem.'))
  18.         self.package = 'sl-modem-daemon'
  19.         self.modem_re = re.compile('^\\s*\\d+\\s*\\[Modem\\s*\\]')
  20.         self.modem_as_subdevice_re = re.compile('^card [0-9].*[mM]odem')
  21.  
  22.     
  23.     def available(self):
  24.         '''Check /proc/asound/cards and aplay -l for a "Modem" card.'''
  25.         if Handler.available(self) == False:
  26.             return False
  27.         
  28.         try:
  29.             for l in open('/proc/asound/cards'):
  30.                 if self.modem_re.match(l):
  31.                     return True
  32.         except IOError:
  33.             Handler.available(self) == False
  34.             e = Handler.available(self) == False
  35.             logging.error('could not open /proc/asound/cards: %s' % str(e))
  36.         except:
  37.             Handler.available(self) == False
  38.  
  39.         
  40.         try:
  41.             aplay = subprocess.Popen([
  42.                 'aplay',
  43.                 '-l'], env = { }, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  44.             (aplay_out, aplay_err) = aplay.communicate()
  45.         except OSError:
  46.             Handler.available(self) == False
  47.             e = Handler.available(self) == False
  48.             logging.error('could not open aplay -l: %s' % str(e))
  49.             return False
  50.  
  51.         if aplay.returncode != 0:
  52.             logging.error('aplay -l failed with %i: %s' % (aplay.returncode, aplay_err))
  53.             return False
  54.         for row in aplay_out.splitlines():
  55.             if self.modem_as_subdevice_re.match(row):
  56.                 return True
  57.         
  58.         return False
  59.  
  60.     
  61.     def used(self):
  62.         if self.enabled():
  63.             pass
  64.         return os.path.exists('/dev/modem')
  65.  
  66.  
  67.